package com.bwie.system.controller;

import cn.hutool.core.util.ObjectUtil;
import com.bwie.common.constants.TokenConstants;
import com.bwie.common.domain.User;
import com.bwie.common.domain.request.UserReqList;
import com.bwie.common.domain.request.UserReqLogin;
import com.bwie.common.domain.request.UserReqSignUp;
import com.bwie.common.exceptions.BizException;
import com.bwie.common.result.Result;
import com.bwie.common.utils.JwtUtils;
import com.bwie.system.service.UserService;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * @Author Junchen_N1
 * @Date 2025/6/17 9:29
 * @ClassName UserController
 * @Description TODO
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Autowired
    private HttpServletRequest request;

    /**
     * 根据用户名和密码查询用户信息
     * @param userReqLogin
     * @return
     */
    @PostMapping("/selectUserByUsernameAndPassword")
    public Result<User> selectUserByUsernameAndPassword(@RequestBody UserReqLogin userReqLogin){
        return userService.selectUserByUsernameAndPassword(userReqLogin);
    }

    @GetMapping("/selectUserFriendsListByUserId")
    public Result<List<User>> selectUserFriendsListByUserId(@RequestParam("userId") Integer userId){
        return userService.selectUserFriendsListByUserId(userId);
    }

    @PostMapping("/sendSmsMsg")
    public Result sendSmsMsg(@RequestParam("tel") @NotBlank(message = "电话号码不能为空") String tel){
        userService.sendSmsMsg(tel);
        return Result.success();
    }

    @GetMapping("/selectUserByUsername/{username}")
    public Result<User> selectUserByUsername(@PathVariable("username") String username){
        return userService.selectUserByUsername(username);
    }

    @GetMapping("/selectUserByTel/{tel}")
    public Result<User> selectUserByTel(@PathVariable("tel") String tel){
        return userService.selectUserByTel(tel);
    }

    @PostMapping("/addUser")
    public Result addUser(@RequestBody UserReqSignUp userReqSignUp){
        userService.addUser(userReqSignUp);
        return Result.success();
    }

    @PostMapping("/selectFriendListByLoginUser")
    public Result<List<User>> selectFriendListByLoginUser(@RequestBody UserReqList userReqList){
        return userService.selectFriendListByLoginUser(userReqList);
    }

    @GetMapping("/deleteFriend")
    public Result deleteFriend(@RequestParam("userId") Integer userId){
        userService.deleteFriend(userId);
        return Result.success();
    }

    @PostMapping("/selectNotMyFriendList")
    public Result<List<User>> selectNotMyFriendList(@RequestBody UserReqList userReqList){
        return userService.selectNotMyFriendList(userReqList);
    }

    @GetMapping("/addFriend/{userId}")
    public Result addFriend(@PathVariable("userId") Integer userId){
        userService.addFriend(userId);
        return Result.success();
    }

    @GetMapping("/getLoginUserMsg")
    public Result<User> getLoginUserMsg(){
        return Result.success(userService.getLoginUserMsgToVue());
    }


}
